-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optimize mload instruction to not allocate a temporary vector #4
optimize mload instruction to not allocate a temporary vector #4
Conversation
@birchmd not sure what's the right workflow here to land the changes. |
core/src/memory.rs
Outdated
@@ -96,6 +96,23 @@ impl Memory { | |||
ret | |||
} | |||
|
|||
/// Get `H256` from a specific offset in memory. | |||
pub fn get_h265(&self, offset: usize) -> H256 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_h256
pub fn get_h265(&self, offset: usize) -> H256 { | ||
let mut ret = [0; 32]; | ||
|
||
#[allow(clippy::needless_range_loop)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could better do smth like
pub fn get_h256(&self, offset: usize) -> H256 {
if offset + 32 < self.data.len() {
H256(self.data.as_slice()[offset..offset + 32] as [u8;32])
} else {
H256::from_slice(&self.get(index, 32));
}
}
This looks like a pretty simple change, should be easy to get it reviewed and merged if we make a PR against the upstream https://github.com/rust-blockchain/evm |
Naked-eye based optimization -- it feels suboptimal to allocate a `Vec` to fetch `[0; u32]`. Running a macro-benchmark in aurora shows that this is about a 1% win, so the compiler probably can't eliminate this vec entirely.
submitted upstream rust-ethereum#97 |
Naked-eye based optimization -- it feels suboptimal to allocate a
Vec
to fetch
[0; u32]
. Running uniswap bench in aurora shows that this isan 1% improvement in wasm cost, so the compiler probably can't eliminate
this vec entirely.